package com.hziee.mail.service;

import com.hziee.mail.dao.GoodDetailRepository;
import com.hziee.mail.dao.GoodsIntroduceImgDirectionaryRepository;
import com.hziee.mail.dao.GoodsSwipeImgDirectionaryRepository;
import com.hziee.mail.model.GoodsDirectionaryEntity;
import com.hziee.mail.model.GoodsIntroduceImgDirectionaryEntity;
import com.hziee.mail.model.GoodsSwipeImgDirectionaryEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ZX
 */
@Service
public class GoodDetailService {

    @Autowired
    private GoodDetailRepository goodDetailRepository;

    @Autowired
    private GoodsIntroduceImgDirectionaryRepository goodsIntroduceImgDirectionaryRepository;

    @Autowired
    private GoodsSwipeImgDirectionaryRepository goodsSwipeImgDirectionaryRepository;


    public HashMap<String, Object> findGoodDetail(String goodId) {
        HashMap<String, Object> map = new HashMap<String, Object>(16);
        List<Map> list = goodDetailRepository.findAllByGoodsId(goodId);
        map.put("goodImages", findGoodInrtoduceImg(goodId));
        map.put("goodSwipe", findGoodSwipeImg(goodId));
        map.put("goodDetails", list);
        return map;
    }

    /*
     * 获取货物的介绍图片
     * */

    private List<GoodsIntroduceImgDirectionaryEntity> findGoodInrtoduceImg(String goodId) {
        List<GoodsIntroduceImgDirectionaryEntity> list = goodsIntroduceImgDirectionaryRepository.findAllByGoodsId(goodId);
        return list;
    }

    /*
     * 获取货物的轮播图片
     * */

    private List<GoodsSwipeImgDirectionaryEntity> findGoodSwipeImg(String goodId) {
        List<GoodsSwipeImgDirectionaryEntity> list = goodsSwipeImgDirectionaryRepository.findAllByGoodsId(goodId);
        return list;
    }
}
